using System;
using System.Diagnostics;

namespace Oracle.ManagedDataAccess.Client
{
	internal class OraclePerfCounterConfiguration
	{
		private static bool CreateCounters(string[] args)
		{
			DeleteCounters(args);
			try
			{
				if (!PerformanceCounterCategory.Exists("ODP.NET, Core Driver"))
				{
					CounterCreationDataCollection list = new CounterCreationDataCollection();
					CreateCounterDataList(ref list);
					string categoryHelp;
					try
					{
						categoryHelp = OracleStringResourceManager.GetErrorMesg(-2801);
					}
					catch (Exception)
					{
						categoryHelp = string.Empty;
					}
					PerformanceCounterCategory.Create("ODP.NET, Core Driver", categoryHelp, PerformanceCounterCategoryType.MultiInstance, list);
				}
			}
			catch
			{
				return false;
			}
			return true;
		}

		private static bool DeleteCounters(string[] args)
		{
			try
			{
				if (PerformanceCounterCategory.Exists("ODP.NET, Core Driver"))
				{
					PerformanceCounterCategory.Delete("ODP.NET, Core Driver");
				}
			}
			catch
			{
				return false;
			}
			return true;
		}

		private static void CreateCounterDataList(ref CounterCreationDataCollection list)
		{
			list.Clear();
			list.Add(new CounterCreationData("HardConnectsPerSecond", OracleStringResourceManager.GetErrorMesg(-2802), PerformanceCounterType.RateOfCountsPerSecond64));
			list.Add(new CounterCreationData("HardDisconnectsPerSecond", OracleStringResourceManager.GetErrorMesg(-2803), PerformanceCounterType.RateOfCountsPerSecond64));
			list.Add(new CounterCreationData("SoftConnectsPerSecond", OracleStringResourceManager.GetErrorMesg(-2804), PerformanceCounterType.RateOfCountsPerSecond64));
			list.Add(new CounterCreationData("SoftDisconnectsPerSecond", OracleStringResourceManager.GetErrorMesg(-2805), PerformanceCounterType.RateOfCountsPerSecond64));
			list.Add(new CounterCreationData("NumberOfActiveConnectionPools", OracleStringResourceManager.GetErrorMesg(-2806), PerformanceCounterType.NumberOfItems64));
			list.Add(new CounterCreationData("NumberOfActiveConnections", OracleStringResourceManager.GetErrorMesg(-2807), PerformanceCounterType.NumberOfItems64));
			list.Add(new CounterCreationData("NumberOfFreeConnections", OracleStringResourceManager.GetErrorMesg(-2808), PerformanceCounterType.NumberOfItems64));
			list.Add(new CounterCreationData("NumberOfInactiveConnectionPools", OracleStringResourceManager.GetErrorMesg(-2809), PerformanceCounterType.NumberOfItems64));
			list.Add(new CounterCreationData("NumberOfNonPooledConnections", OracleStringResourceManager.GetErrorMesg(-2810), PerformanceCounterType.NumberOfItems64));
			list.Add(new CounterCreationData("NumberOfPooledConnections", OracleStringResourceManager.GetErrorMesg(-2811), PerformanceCounterType.NumberOfItems64));
			list.Add(new CounterCreationData("NumberOfReclaimedConnections", OracleStringResourceManager.GetErrorMesg(-2812), PerformanceCounterType.NumberOfItems64));
			list.Add(new CounterCreationData("NumberOfStasisConnections", OracleStringResourceManager.GetErrorMesg(-2813), PerformanceCounterType.NumberOfItems64));
		}
	}
}
